package com.slf.demo.openapi.controller;

import com.slf.demo.openapi.vo.UserVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

/**
 * @author slf
 * @date 2021/8/12
 */
@Tag(name = "DemoController", description = "OpenApi 测试接口")
@RestController
@RequestMapping("demo")
public class DemoController {
    @Operation(
            summary = "demoGet",
            description = "详细说明demoGet",
            parameters ={
                    //参数名称 描述 所在位置
                    @Parameter(name="name",description = "姓名",in= ParameterIn.PATH),
                    @Parameter(name="age",description = "年龄",in= ParameterIn.PATH)
            })
    @GetMapping("/get/{name}/{age}")
    public UserVo demoGet(@PathVariable("name") String name, @PathVariable("age") String age){
        System.out.println(name +"/"+age);
        return new UserVo(name,age);
    }

    @Operation(summary = "demoPost",requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "shiti"))
    @PostMapping("post")
    public UserVo demoPost(@RequestBody UserVo vo){
        System.out.println(vo.toString());
        return vo;
    }

    @PutMapping("put")
    public String demoPut(){
        return null;
    }
    @DeleteMapping("delete")
    public String demoDelete(){
        return null;
    }
    @RequestMapping(value = "options",method = RequestMethod.OPTIONS)
    public String demoOptions(){
        return null;
    }
}
